package org.struts.mvc.servlet;

import java.io.IOException;

import javax.servlet.ServletContext;
import javax.servlet.ServletContextEvent;
import javax.servlet.ServletContextListener;

import org.jdom.JDOMException;
import org.struts.mvc.util.StrutsRequestUtil;

public class ActionListener implements ServletContextListener{

	public void contextInitialized(ServletContextEvent sce) {
		
		ServletContext context = sce.getServletContext();
		String configPath = context.getInitParameter("struts-config");
		System.out.println("configPath=="+configPath);
		String tomcatpath = context.getRealPath("//");
		System.out.println("tomcatpath=="+tomcatpath);
		
		try {
			//初始化
			StrutsRequestUtil.initStrutsConfig(tomcatpath + configPath);
			context.setAttribute("struts", StrutsRequestUtil.STRUTS_CONFIG_MAPPING);
		} catch (JDOMException e) {
			e.printStackTrace();
		} catch (IOException e) {
			e.printStackTrace();
		}
	}

	public void contextDestroyed(ServletContextEvent sce) {
		System.out.println("注销");
	}

}
